package LeetCode.exercise;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LC17 {
    List<String> res = new ArrayList<>();
    StringBuilder sb = new StringBuilder();
    Map<Character, String> map = new HashMap<>();

    public List<String> letterCombinations(String digits) {
        map.put('1', "");
        map.put('2', "abc");
        map.put('3', "def");
        map.put('4', "ghi");
        map.put('5', "jkl");
        map.put('6', "mno");
        map.put('7', "pqrs");
        map.put('8', "tuv");
        map.put('9', "wxyz");
        if(digits == null || digits.isEmpty()){
            return res;
        }
        bfs(0, digits);
        return res;
    }

    public void bfs(int cur, String digits) {
        if (cur == digits.length()) {
            res.add(sb.toString());
            return;
        }
        String str = map.get(digits.charAt(cur));
        for (int i = 0; i < str.length(); i++) {
            sb.append(str.charAt(i));
            bfs(cur + 1, digits);
            sb.deleteCharAt(sb.length() - 1);
        }
    }

    public static void main(String[] args) {
        LC17 lc = new LC17();
        System.out.println(lc.letterCombinations(""));
    }
}
